package com.sunlands.zlcx.usercenter.config;

import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.paths.RelativePathProvider;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.ServletContext;

@EnableSwagger2
@Configuration
@ConfigurationProperties(prefix = "swagger")
@Setter
public class SwaggerConfiguration {

    @Value("${swagger.title}")
    String title;

    @Value("${swagger.host}")
    String host;

    @Value("${swagger.description}")
    String description;

    @Value("${swagger.basePackage}")
    String basePackage;

    @Value("${swagger.version}")
    String version;

    @Value("${swagger.contact.name}")
    String contactName;

    @Value("${swagger.contact.email}")
    String contactEmail;



    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .host(host)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
//                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .contact(new Contact(contactName, null, contactEmail))
                .description(description)
                .version(version)
                .build();
    }

}
